#pragma once

#include "ffmpegTypes.h"
#include <string>
#include <memory>
#include <thread>
#include <atomic>
#include <future>
//#include "Common/timer/unit_timer.hpp"
#define _CAPTURE_STATISTICAL 0
class  AVPacket;
class CE_API MediaSourceEvent
{
public:	

	virtual void OnSourceConnected(void* arg, const std::map<std::string, std::string>& opts) = 0;
	virtual bool onNewSession(const char* id, const char* media, const char* codec, const char* sdp, unsigned int rtpfrequency, unsigned int channels) = 0;
	virtual void OnSourceDisConnected(int err) =0;
	virtual void OnSourceVideoPacket(const char* id, AVPacket* packet) = 0;
	virtual void OnSourceAudioPacket(const char* id, AVPacket* packet) = 0;
	virtual void OnSourceVideoPacket(const char* id, uint8_t* aBytes, int aSize, int64_t ts, bool bKey) = 0;
	virtual void OnSourceAudioPacket(const char* id, uint8_t* aBytes, int aSize, int64_t ts) = 0;
	virtual bool OnIsQuitCapture() = 0;
};
class CE_API MediaSourceAPI
{
public:
	static MediaSourceAPI* CreateMediaSource(std::string url, MediaSourceEvent* callback, bool capture_video, bool capture_audio);
	
	virtual ~MediaSourceAPI() {};

	static void deleteMediaSource(MediaSourceAPI* source);

	static bool GetStreamInfo(const char* url, std::map<std::string, std::string>& opts);

	virtual void SyncStop(void)=0;

	virtual void Run(bool sync)=0;

	static bool captureYUVFrame(const std::string& videoStreamUrl, uint8_t** yuvData, int& width, int& height);

	static bool captureYUVFrames(const std::string& videoStreamUrl, int frameCount, std::vector<uint8_t*>& yuvFrames, int& width, int& height);

};
